import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by hansheng11 on 2019/12/2 15:17.
 */
public class 第6题_Z字型变换 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String str = sc.next();
            int num = sc.nextInt();
            System.out.println(convert(str, num));
        }
    }

    public static String convert(String s, int numRows) {
        if (s == null || "".equals(s)) {
            return "";
        }
        if (numRows <= 1) {
            return s;
        }
        int length = s.length();
        List<StringBuilder> rows = new ArrayList<>();
        for (int i = 0; i < Math.min(numRows, length); i++) {
            rows.add(new StringBuilder());
        }
        int curRow = 0;
        boolean goDown = false;
        for (char c : s.toCharArray()) {
            rows.get(curRow).append(c);
            if (curRow == 0 || curRow == rows.size() - 1) {
                goDown = !goDown;
            }
            curRow += goDown ? 1 : -1;
        }

        StringBuilder stringBuilder = new StringBuilder();
        for (StringBuilder sb : rows) {
            stringBuilder.append(sb);
        }
        return stringBuilder.toString();
    }
}
